package us.mooresr.geartrack.server.handler;

import com.gwtplatform.dispatch.server.actionhandler.ActionHandler;

import us.mooresr.geartrack.server.DAO;
import us.mooresr.geartrack.shared.action.DeletePersonAction;
import us.mooresr.geartrack.shared.action.DeletePersonResult;

import com.google.inject.Inject;
import com.gwtplatform.dispatch.server.ExecutionContext;
import com.gwtplatform.dispatch.shared.ActionException;

public class DeletePersonActionHandler implements
		ActionHandler<DeletePersonAction, DeletePersonResult> {

	@Inject
	public DeletePersonActionHandler() {
	}

	@Override
	public DeletePersonResult execute(DeletePersonAction action, ExecutionContext context)
			throws ActionException {
		DAO dao = new DAO();
		
		dao.ofy().delete(action.getPersonIn());
		
		return new DeletePersonResult(action.getPersonIn());
	}

	@Override
	public void undo(DeletePersonAction action, DeletePersonResult result,
			ExecutionContext context) throws ActionException {
	}

	@Override
	public Class<DeletePersonAction> getActionType() {
		return DeletePersonAction.class;
	}
}
